package com.ujiuye.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class Demo05Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置字符集
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String username = req.getParameter("username");
        //只要用户名不为空  就算登录成功
        if(username != null && !"".equals(username)) {
            //登录成功
            req.getSession().setAttribute("username",username);
            resp.sendRedirect("demo06_main.jsp");
        }else {
            //登录失败
            resp.sendRedirect("demo05_login.jsp");
        }
    }
}
